package jdk8;

import java.beans.XMLDecoder;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.function.Supplier;
import java.util.*;
/**
 * @author oldliu
 * @since 1.0
 */
public class SupplierTest {
    public static void main(String[] args) {
        Supplier<Integer> t=()->(int)(1000*Math.random());
        System.out.println(t.get());
        List<String> p2=new ArrayList<>();
        List<String> products = getProducts(() -> {
            List<String> d = new ArrayList<>();
            d.add("苹果");
            d.add("大白兔");
            return d;
            //return p2;
        });
        System.out.println(products);
    }
    public static List<String> getProducts(Supplier<List<String>> s){
        try {
            XMLDecoder xd=new XMLDecoder(new FileInputStream("product.xml"));
            Object o = xd.readObject();
            xd.close();
            return (List<String>) o;
        } catch (Exception e) {
            //e.printStackTrace();
        }
        return s.get();
    }
}

